* Additional GSS analysis for: 
* Class, Policy Attitudes and U.S. Presidential Voting in the Post-Industrial Era: The Importance of Issue Salience
* Franko & Witko
* Political Research Quarterly
* Date: 05/25/22


*******************************************************************************
* Race policy index.
* Pooled models.
*******************************************************************************

* Create new frame to save results.
frame create raceG_diffs_ALT
frame raceG_diffs_ALT { 
	input 	str10 var diff ll ul str10 sample
		"egp1.5" . . . "All"
		"egp2.5" . . . "All"
		"inc5" . . . "All"
		"edu5" . . . "All"
		"white" . . . "All"
		"subclass" . . . "All"
		"egp1.5" . . . "White"
		"egp2.5" . . . "White"
		"inc5" . . . "White"
		"edu5" . . . "White"
		"subclass" . . . "White"
		"egp1.5" . . . "Nonwhite"
		"egp2.5" . . . "Nonwhite"
		"inc5" . . . "Nonwhite"
		"edu5" . . . "Nonwhite"
		"subclass" . . . "Nonwhite"
	end
}



*******************************************************************************
* Full sample.
*******************************************************************************

local varlst1 "white age female south"

foreach v in b5.egp5 inc5 edu5 subclass {
	if "`v'" == "b5.egp5" {
		mixed racepol01 `v' `varlst1' || year: , reml
		estimates store raceG_egp5_all_ALT
		margins , at(egp5=5) at(egp5=1) post
		lincom _b[1._at] - _b[2._at]
		frame raceG_diffs_ALT { 
			replace diff = r(estimate) if var == "egp1.5" & sample == "All"
			replace ll = r(estimate) + invnorm(0.025)*r(se) if var == "egp1.5" & sample == "All"
			replace ul = r(estimate) + invnorm(0.975)*r(se) if var == "egp1.5" & sample == "All"
		}
		estimates restore raceG_egp5_all_ALT
		margins , at(egp5=5) at(egp5=2) post
		lincom _b[1._at] - _b[2._at]
		frame raceG_diffs_ALT {
			replace diff = r(estimate) if var == "egp2.5" & sample == "All"
			replace ll = r(estimate) + invnorm(0.025)*r(se) if var == "egp2.5" & sample == "All"
			replace ul = r(estimate) + invnorm(0.975)*r(se) if var == "egp2.5" & sample == "All"
		}
	}
	else {
		mixed racepol01 `v' `varlst1' || year: , reml
		estimates store raceG_`v'_all_ALT
		margins , at((p5) `v') at((p95) `v') post
		lincom _b[1._at] - _b[2._at]
		frame raceG_diffs_ALT { 
			replace diff = r(estimate) if var == "`v'" & sample == "All"
			replace ll = r(estimate) + invnorm(0.025)*r(se) if var == "`v'" & sample == "All"
			replace ul = r(estimate) + invnorm(0.975)*r(se) if var == "`v'" & sample == "All"
		}
	}
}

* Full sample, race without class covariates.
mixed racepol01 `varlst1' || year: , reml
estimates store raceG_white_all_ALT
* Difference for white/non-white.
margins , at(white=0) at(white=1) post
lincom _b[1._at] - _b[2._at]
frame raceG_diffs_ALT {
	replace diff = r(estimate) if var == "white" & sample == "All"
	replace ll = r(estimate) + invnorm(0.025)*r(se) if var == "white" & sample == "All"
	replace ul = r(estimate) + invnorm(0.975)*r(se) if var == "white" & sample == "All"
}


* Full sample, include all covariates.
mixed racepol01 b5.egp5 inc5 edu5 subclass `varlst1' || year: , reml
estimates store raceG_full_all_ALT



*******************************************************************************
* Repeat above analysis for white only subsample.
*******************************************************************************

local varlst2 "age female south"

foreach v in b5.egp5 inc5 edu5 subclass {
	if "`v'" == "b5.egp5" {
		mixed racepol01 `v' `varlst2' || year: if white==1 , reml
		estimates store raceG_egp5_wo_ALT
		margins , at(egp5=5) at(egp5=1) post
		lincom _b[1._at] - _b[2._at]
		frame raceG_diffs_ALT { 
			replace diff = r(estimate) if var == "egp1.5" & sample == "White"
			replace ll = r(estimate) + invnorm(0.025)*r(se) if var == "egp1.5" & sample == "White"
			replace ul = r(estimate) + invnorm(0.975)*r(se) if var == "egp1.5" & sample == "White"
		}
		estimates restore raceG_egp5_wo_ALT
		margins , at(egp5=5) at(egp5=2) post
		lincom _b[1._at] - _b[2._at]
		frame raceG_diffs_ALT {
			replace diff = r(estimate) if var == "egp2.5" & sample == "White"
			replace ll = r(estimate) + invnorm(0.025)*r(se) if var == "egp2.5" & sample == "White"
			replace ul = r(estimate) + invnorm(0.975)*r(se) if var == "egp2.5" & sample == "White"
		}
	}
	else {
		mixed racepol01 `v' `varlst2' || year: if white==1 , reml
		estimates store raceG_`v'_wo_ALT
		margins , at((p5) `v') at((p95) `v') post
		lincom _b[1._at] - _b[2._at]
		frame raceG_diffs_ALT { 
			replace diff = r(estimate) if var == "`v'" & sample == "White"
			replace ll = r(estimate) + invnorm(0.025)*r(se) if var == "`v'" & sample == "White"
			replace ul = r(estimate) + invnorm(0.975)*r(se) if var == "`v'" & sample == "White"
		}
	}
}


* White only subsample, include all covariates.
mixed racepol01 b5.egp5 inc5 edu5 subclass `varlst2' || year: if white==1 , reml
estimates store raceG_full_wo_ALT



***** Save Min/max difference results.
frame raceG_diffs_ALT : save "results/raceG_diffs_ALT.dta", replace





*******************************************************************************
* Race policy index.
* Allow social class coefficients to vary by year, then plot effects over time.
*******************************************************************************

*******************************************************************************
* Whites only subsample.
*******************************************************************************

local varlst2 "age female south"

* EGP social class.
mixed racepol01 egp5_1-egp5_4 `varlst2' || year: egp5_1-egp5_4 if white == 1 , reml
estimates store raceG_egp_T_wo_ALT

* Estimated effects: use coefficients.
preserve
gen b_egp = .
gen se_egp = .

predict egp_re* if e(sample), reffects reses(egp_rese*)

foreach n of numlist 1(1)4 {
	replace b_egp = _b[egp5_`n'] + egp_re`n' if egp5_`n' == 1
	replace se_egp = sqrt((_se[egp5_`n']^2) + (egp_rese`n'^2)) if egp5_`n' == 1
}

collapse b_egp se_egp, by(year egp5)
gen b_egp_hi = b_egp + 1.96*se_egp
gen b_egp_lo = b_egp - 1.96*se_egp

drop if b_egp == .

save "results/raceG_egp5_T_wo_ALT.dta", replace
restore


* All other class variables.
foreach v in inc5 edu5 subclass {
	mixed racepol01 `v' `varlst2' || year: `v' if white == 1 , reml
	estimates store raceG_`v'_T_wo_ALT
	* Estimated effects: use coefficients.
	preserve
	predict b_re* if e(sample), reffects reses(b_rese*)

	gen b = _b[`v'] + b_re1
	gen se = sqrt((_se[`v']^2) + (b_rese1^2))

	collapse b se, by(year)
	gen b_hi = b + 1.96*se
	gen b_lo = b - 1.96*se

	drop if b == .
	gen str20 var = "`v'"

	save "results/raceG_`v'_T_wo_ALT.dta", replace
	restore
}



